﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace AzureBlob
{
    class CloudBlobContainerHolder : ICloudBlobHolder
    {
        CloudBlobContainer container = null;
        BlobContainerPermissions permissions = null;
        //BlobContainerPublicAccessType? accessType = null;
        public CloudBlobContainerHolder(CloudBlobContainer container)
        {
            this.container = container;
        }

        public Uri Uri
        {
            get { return container.Uri; }
        }


        public CloudBlockBlob GetBlockBlobReference(string relUri)
        {
            return container.GetBlockBlobReference(relUri);
        }

        public IEnumerable<IListBlobItem> ListBlobs()
        {
            return container.ListBlobs();
        }

        public IAsyncResult BeginListBlobsSegmented(AsyncCallback callback, object state)
        {
            return container.BeginListBlobsSegmented(callback, state);
        }

        public ResultSegment<IListBlobItem> EndListBlobsSegmented(IAsyncResult asyncResult)
        {
            return container.EndListBlobsSegmented(asyncResult);
        }

        public CloudBlobDirectory GetDirectoryReference(string relativeAddress)
        {
            return container.GetDirectoryReference(relativeAddress);
        }

        public IEnumerable<IListBlobItem> ListBlobs(BlobRequestOptions options)
        {
            return container.ListBlobs(options);
        }

        public void Delete()
        {
            container.Delete();
        }

        internal BlobContainerPublicAccessType GetPermissions()
        {
            if (permissions == null)
                permissions = container.GetPermissions();
            return permissions.PublicAccess;
        }

        internal void SetPermissions(BlobContainerPublicAccessType blobContainerPublicAccessType)
        {
            permissions.PublicAccess = blobContainerPublicAccessType;
            container.SetPermissions(permissions);
        }
    }
}
